<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ include file="/WEB-INF/decorators/taglibs.jsp"%>
<!DOCTYPE HTML>
<html>
<head>
<!-- Force latest IE rendering engine or ChromeFrame if installed -->
<!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"><![endif]-->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>${pageTitle}</title>
<script type="text/javascript" src="${appPath}/js/jquery-1.10.2.min.js"></script>
<script type="text/javascript"
	src="${appPath}/js/jquery-ui-1.9.2.custom.min.js"></script>
<script type="text/javascript" src="${appPath}/js/jquery.easyui.min.js"></script>
<script type="text/javascript"
	src="${appPath}/js/locale/easyui-lang-zh_TW.js"></script>
<!-- default -->
<link rel="stylesheet" type="text/css" id="ui_css"
	href="${appPath}/themes/metro-blue/easyui2.css" />
<link rel="stylesheet" type="text/css" href="${appPath}/css/css2.css" />
<link rel="stylesheet" type="text/css" id="icon_css"
	href="${appPath}/themes/icon.css" />
<!-- Bootstrap styles -->
<link rel="stylesheet"
	href="${appPath}/css/fileUpload/bootstrap.min.css">
<!-- blueimp Gallery styles -->
<link rel="stylesheet"
	href="${appPath}/css/fileUpload/blueimp-gallery.min.css">
<!-- Generic page styles -->
<link rel="stylesheet" href="${appPath}/css/fileUpload/style.css">
<!-- CSS to style the file input field as button and adjust the Bootstrap progress bars -->
<link rel="stylesheet"
	href="${appPath}/css/fileUpload/jquery.fileupload.css">
<link rel="stylesheet"
	href="${appPath}/css/fileUpload/jquery.fileupload-ui.css">
</head>
<body style="padding: 30px;">
	<div class="container">
		<h2>第${fileForm.sessionNo}期檔案管理</h2>
		<!-- download form -->
		<form:form method="post" id="fileForm" modelAttribute="fileForm" action="${appPath}/files/exp.htm">
			<form:hidden id="sessionNo" path="sessionNo" />
			<form:hidden id="filename" path="filename" />
		</form:form>
		<!-- The file upload form used as target for the file upload widget -->
		<form id="fileupload" action="${appPath}/files/save.json"
			method="POST" enctype="multipart/form-data">
			<input type="hidden" id="sNo" name="sNo" value="${fileForm.sessionNo}" />	
			<!-- Redirect browsers with JavaScript disabled to the origin page -->
			<noscript>
				<input type="hidden" name="redirect"
					value="${appPath}/files/save.json">
			</noscript>
			<!-- The fileupload-buttonbar contains buttons to add/delete files and start/cancel the upload -->
			<div class="row fileupload-buttonbar">
				<div>
					<!-- The fileinput-button span is used to style the file input field as button -->
					<span class="btn btn-success fileinput-button"> <span>新增檔案...</span>
						<input type="file" name="files[]" multiple>
					</span>
					<button type="submit" class="btn btn-primary start">
						<span>上傳</span>
					</button>
					<button type="reset" class="btn btn-warning cancel">
						<span>取消</span>
					</button>
					<button type="button" class="btn btn-danger delete">
						<span>刪除</span>
					</button>
					<input type="checkbox" class="toggle">
					<!-- The global file processing state -->
					<span class="fileupload-process"></span>
				</div>
				<!-- The global progress state -->
				<div class="col-lg-5 fileupload-progress fade">
					<!-- The global progress bar -->
					<div class="progress progress-striped active" role="progressbar"
						aria-valuemin="0" aria-valuemax="100">
						<div class="progress-bar progress-bar-success" style="width: 0%;"></div>
					</div>
					<!-- The extended global progress state -->
					<div class="progress-extended">&nbsp;</div>
				</div>
			</div>
			<!-- The table listing the files available for upload/download -->
			<table role="presentation" class="table table-striped">
				<tbody class="files"></tbody>
			</table>
		</form>
	</div>

	
	<!-- The template to display files available for upload -->
	<script id="template-upload" type="text/x-tmpl">
{% for (var i=0, file; file=o.files[i]; i++) { %}
    <tr class="template-upload fade">
		<td>
			{%=i+1%}
		</td>
        <td>
            <p>{%=file.name%}</p>
            <strong class="error text-danger"></strong>
        </td>
        <td>
            <p class="size">Processing...</p>
            <div class="progress progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0"><div class="progress-bar progress-bar-success" style="width:0%;"></div></div>
        </td>
        <td>
            {% if (!i && !o.options.autoUpload) { %}
                <button class="btn btn-primary start" disabled>上傳</button>
            {% } %}
            {% if (!i) { %}
                <button class="btn btn-warning cancel">取消</button>
            {% } %}
        </td>
    </tr>
{% } %}
</script>
<!-- The template to display files available for download -->
<script id="template-download" type="text/x-tmpl">
{% for (var i=0, file; file=o.files[i]; i++) { %}
    <tr class="template-download fade">
		<td width="5%">
			{%=i+1%}
		</td>
        <td> 
            <p>
                {% if (file.url) { %}
                    <a href="javascript:download('{%=file.url%}');" title="{%=file.name%}">{%=file.name%}</a>
                {% } else { %}
                    <span>{%=file.name%}</span>
                {% } %}
            </p>
            {% if (file.error) { %}
                <div><span class="label label-danger">Error</span> {%=file.error%}</div>
            {% } %}
        </td>
        <td>
            <span class="size">{%=o.formatFileSize(file.size)%}</span>
        </td>
        <td>
            {% if (file.name) { %}
                <button class="btn btn-danger delete" data-type="{%=file.deleteType%}" onclick="doDel('{%=file.url%}');">
					刪除
                </button>
            {% } %}
        </td>
    </tr>
{% } %}
</script>
	<script type="text/javascript">
		function download(fileName) {
			$("#filename").val(fileName);
			$("#fileForm").submit();
		}
		function doDel(id) {
			if (confirm('確定刪除')) {
				$.post('${appPath}/files/delete.json', {
					id : id,
					sessionNo : '${fileForm.sessionNo}'
				}, function(data) {
					if(!eval(data)){
						alert("刪除失敗");
					}
				});
			}
		}
	</script>
	<!-- The jQuery UI widget factory, can be omitted if jQuery UI is already included -->
	<script src="${appPath}/js/fileUpload/vendor/jquery.ui.widget.js"></script>
	<!-- The Templates plugin is included to render the upload/download listings -->
	<script src="${appPath}/js/fileUpload/tmpl.min.js"></script>
	<!-- The Load Image plugin is included for the preview images and image resizing functionality -->
	<script src="${appPath}/js/fileUpload/load-image.all.min.js"></script>
	<!-- The Canvas to Blob plugin is included for image resizing functionality -->
	<script src="${appPath}/js/fileUpload/canvas-to-blob.min.js"></script>
	<!-- Bootstrap JS is not required, but included for the responsive demo navigation -->
	<script src="${appPath}/js/fileUpload/bootstrap.min.js"></script>
	<!-- blueimp Gallery script -->
	<script src="${appPath}/js/fileUpload/jquery.blueimp-gallery.min.js"></script>
	<!-- The Iframe Transport is required for browsers without support for XHR file uploads -->
	<script src="${appPath}/js/fileUpload/jquery.iframe-transport.js"></script>
	<!-- The basic File Upload plugin -->
	<script src="${appPath}/js/fileUpload/jquery.fileupload.js"></script>
	<!-- The File Upload processing plugin -->
	<script src="${appPath}/js/fileUpload/jquery.fileupload-process.js"></script>
	<!-- The File Upload validation plugin -->
	<script src="${appPath}/js/fileUpload/jquery.fileupload-validate.js"></script>
	<!-- The File Upload user interface plugin -->
	<script src="${appPath}/js/fileUpload/jquery.fileupload-ui.js"></script>
	<!-- The main application script -->
	<script src="${appPath}/js/fileUpload/main.js"></script>
	<!-- The XDomainRequest Transport is included for cross-domain file deletion for IE 8 and IE 9 -->
	<!--[if (gte IE 8)&(lt IE 10)]>
<script src="${appPath}/js/fileUpload/cors/jquery.xdr-transport.js"></script>
<![endif]-->

</body>
</html>